import 'package:flutter/material.dart';
import '../../projectUser/views/project_user_view.dart';
import '../../interface/views/interface_view.dart';

import 'package:get/get.dart';
import '../../../../widget/avatarPopupMenu.dart';
import '../../../../services/screenAdapter.dart';

import '../controllers/project_main_controller.dart';

class ProjectMainView extends GetView {
  ProjectMainView({super.key});

  final ProjectMainController controller = Get.put(ProjectMainController());
  
  Widget _buildTab(value) {
    return InkWell(
      onTap: () {
        controller.changeSelectedTabsIndex(value["id"]);
      },
      child: Container(
        padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: value["id"] == controller.currentTabIndex.value
                  ? const Color(0xFF1890FF)
                  : Colors.transparent,
              width: ScreenAdapter.width(2),
            ),
          ),
        ),
        child: Text(
          "${value["title"]}",
          style: TextStyle(
            fontWeight: FontWeight.w500,
            fontSize: ScreenAdapter.fontSize(16),
            color: value["id"] == controller.currentTabIndex.value
                ? Colors.black
                : const Color(0xFF666666),
          ),
        ),
      ),
    );
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        title: Text("Flutter Api", style: TextStyle(color: Colors.white)),
        backgroundColor: Colors.black,
        automaticallyImplyLeading: false, //
        // centerTitle: true,
        actions: [AvatarPopupMenu()],
      ),
      body:Column(
        children: [
          Container(
            padding: EdgeInsets.only(left: ScreenAdapter.width(20)),
            color: Colors.white,
            child: Obx(
              () => Row(
                children: controller.tabsList.map((value) {
                  return _buildTab(value);
                }).toList(),
              ),
            ),
          ),
          // 内容区域
          Expanded(
            child: Container(
              color: Colors.white,
              child: Obx(() {
                switch (controller.currentTabIndex.value) {
                  case 1:
                    return InterfaceView(projectId: controller.projectId);
                  case 2:
                    return ProjectUserView(projectId: controller.projectId);
                  // case 3:
                  //   return _buildActivityTab();
                  // case 4:
                  //   return _buildSettingsTab();
                  default:
                    return const Center(child: Text('页面加载中'));
                }
              }),
            ),
          ),
        ],
      ),
    );
  }
}
